package com.bbzn.device.client.utils;

import java.math.BigDecimal;
import java.math.BigInteger;

/**
 * @Author wulongbo
 * @Date 2021/12/31 17:37
 * @Version 1.0
 */
public class HexUtil {

    private static BigDecimal initial = new BigDecimal("25");
    private static BigDecimal end = new BigDecimal("30");
    private static BigDecimal multiply = new BigDecimal("100");

    public static int hex16To10(String strHex) {
        return new BigInteger(strHex, 16).intValue();
    }

    public static String hex10To16(int valueTen) {
        return String.format("%08X", valueTen);
    }

    public static int percentage(BigDecimal decimal) {
        BigDecimal result = decimal.subtract(initial).divide(end.subtract(initial)).multiply(multiply);
        return result.compareTo(new BigDecimal("0")) > 0 ? result.intValue() : 0;
    }

//    public static void main(String[] args) {
//
//
//        String data = Base64Util.encode("qt0LJwDACGhRECAAAAARAA4ADS0AAAAAAAAAJGsLVQ==");
//        System.out.println("data:" + data);
//
//
//        // 03625234324441
//        String test = "aadd0b2700c1086851102000000011000e000d2d000000000000001e6b0b55";
//        String result = test.substring(54, 56);
//        System.out.println("截取电量：" + result);
//        BigDecimal decimal = new BigDecimal(String.valueOf(hex16To10(result)));
//        System.out.println("当前电量：" + decimal);
//        System.out.println("电量：" + percentage(decimal));
//        System.out.println(decimal.divide(new BigDecimal("10"), 1, BigDecimal.ROUND_UNNECESSARY));
////        String imei=test.substring(12,27);
//
////        System.out.println(imei);
////        System.out.println(hex16To10(result));
//        System.out.println(hex16To10("C5"));
//
////        BigDecimal d=new BigDecimal("-20");
////        System.out.println(d.compareTo(new BigDecimal("0")) > 0 ? d.intValue() : 0);
//    }
}
